package com.gash.scrape.data;

import java.util.ArrayList;

/**
 * Information about a link.
 * 
 * TODO should the keywords contain a count of its frequency in the anchor text?
 * 
 * @author gash1
 * 
 */
public class Link {
	public enum LinkType {
		Text, Image
	};

	private String url;
	private LinkType type;
	private int count;
	private boolean citation; // really for papers or wikipedia
	private ArrayList<String> keywords;

	public void addKeyword(String w) {
		if (w == null || w.length() == 0)
			return;
		else if (keywords == null)
			keywords = new ArrayList<String>();

		w = w.trim().toLowerCase();
		if (!keywords.contains(w))
			keywords.add(w);
	}

	public void merge(Link link) {
		if (!this.url.equalsIgnoreCase(link.getUrl()))
			return;

		this.count += link.count;
		if (this.type != link.type && link.type != null) {
			// TODO should we track both?
			this.type = LinkType.Text;
		}

		if (keywords != null) {
			if (this.keywords == null) {
				this.keywords = new ArrayList<String>();
				this.keywords.addAll(link.keywords);
			} else if (link.keywords != null) {
				for (String k : link.keywords) {
					if (!keywords.contains(k))
						this.keywords.add(k);
				}
			}
		}
	}

	public String getUrl() {
		return url;
	}

	public void setUrl(String url) {
		this.url = url;
	}

	public LinkType getType() {
		return type;
	}

	public void setType(LinkType type) {
		this.type = type;
	}

	public ArrayList<String> getKeywords() {
		return keywords;
	}

	public void setKeywords(ArrayList<String> keywords) {
		this.keywords = keywords;
	}

	public int getCount() {
		return count;
	}

	public void setCount(int count) {
		this.count = count;
	}

	public boolean isCitation() {
		return citation;
	}

	public void setCitation(boolean citation) {
		this.citation = citation;
	}
}
